From 8f78bcc7537f18a0b2bb29c34fe3e18f2def3feb Mon Sep 17 00:00:00 2001 From: robertl Date: Thu, 26 Oct 2006 23:07:01 +0000 Subject: [PATCH] Improvements in text and html output from Scott Brynen. --- defs.h | 1 + html.c | 122 ++++++++++-------- text.c | 73 ++++++----- util.c | 67 ++++++++-- xmldoc/formats/options/kml-labels.xml | 4 + .../options/kml-max_position_points.xml | 4 + 6 files changed, 178 insertions(+), 93 deletions(-) create mode 100644 xmldoc/formats/options/kml-labels.xml create mode 100644 xmldoc/formats/options/kml-max_position_points.xml diff --git a/defs.h b/defs.h index 356a7deb4..0bb9a2e87 100644 --- a/defs.h +++ b/defs.h @@ -715,6 +715,7 @@ char * strip_html(const utf_string*); char * strip_nastyhtml(const char * in); char * convert_human_date_format(const char *human_datef); /* "MM,YYYY,DD" -> "%m,%Y,%d" */ char * convert_human_time_format(const char *human_timef); /* "HH+mm+ss" -> "%H+%M+%S" */ +char * pretty_deg_format(double lat, double lon, char fmt, int html); /* decimal -> dd.dddd or dd mm.mmm or dd mm ss */ /* * Character encoding transformations. diff --git a/html.c b/html.c index 46874ed55..3d7f110c4 100644 --- a/html.c +++ b/html.c @@ -30,6 +30,8 @@ static short_handle mkshort_handle; static char *stylesheet = NULL; static char *encrypt = NULL; static char *includelogs = NULL; +static char *degformat = NULL; +static char *altunits = NULL; #define MYNAME "HTML" @@ -41,6 +43,10 @@ arglist_t html_args[] = { "Encrypt hints using ROT13", NULL, ARGTYPE_BOOL, ARG_NOMINMAX }, { "logs", &includelogs, "Include groundspeak logs if present", NULL, ARGTYPE_BOOL, ARG_NOMINMAX }, + { "degformat", °format, + "Degrees output as 'ddd', 'dmm'(default) or 'dms'", "dmm", ARGTYPE_STRING, ARG_NOMINMAX }, + { "altunits", &altunits, + "Units for altitude (f)eet or (m)etres", "m", ARGTYPE_STRING, ARG_NOMINMAX }, ARG_TERMINATOR }; @@ -63,16 +69,15 @@ wr_deinit(void) static void html_disp(const waypoint *wpt) { - int latint, lonint; char tbuf[1024]; + char *cout; time_t tm = wpt->creation_time; gbint32 utmz; double utme, utmn; char utmzc; fs_xml *fs_gpx = NULL; - lonint = abs((int) wpt->longitude); - latint = abs((int) wpt->latitude); + GPS_Math_WGS84_To_UTM_EN(wpt->latitude, wpt->longitude, &utme, &utmn, &utmz, &utmzc); @@ -81,17 +86,15 @@ html_disp(const waypoint *wpt) strftime(tbuf, sizeof(tbuf), "%d-%b-%Y", localtime(&tm)); - fprintf(file_out, "
\n"); - fprintf(file_out, "
\n", wpt->shortname); - fprintf(file_out, "

%s - %c%d°%06.3f %c%d°%06.3f (%d%c %6.0f %7.0f)", - (global_opts.synthesize_shortnames) ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname, - wpt->latitude < 0 ? 'S' : 'N', latint, 60.0 * (fabs(wpt->latitude) - latint), - wpt->longitude < 0 ? 'W' : 'E', lonint, 60.0 * (fabs(wpt->longitude) - lonint), - utmz, utmzc, utme, utmn); - if (wpt->altitude != unknown_alt) - fprintf (file_out, " alt: %1.1f", wpt->altitude); + fprintf(file_out, "\n
\n", wpt->shortname); + fprintf(file_out, "\n"); + fprintf(file_out, "\n"); + + fprintf (file_out, "\n"); + + + fprintf(file_out, "

%s - ",(global_opts.synthesize_shortnames) ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname); + cout = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], 1); + fprintf(file_out, "%s (%d%c %6.0f %7.0f)", cout, utmz, utmzc, utme, utmn); + xfree (cout); + if (wpt->altitude != unknown_alt) + fprintf (file_out, " alt:%d", (int) ( (altunits[0]=='f')?METERS_TO_FEET(wpt->altitude):wpt->altitude) ); fprintf (file_out, "
\n"); - if (strcmp(wpt->description, wpt->shortname)) { if (wpt->url) { char *d = html_entitize(wpt->description); @@ -100,36 +103,47 @@ html_disp(const waypoint *wpt) } else { fprintf(file_out, "%s", wpt->description); + } + if (wpt->gc_data.placer) { + fprintf(file_out, " by %s", wpt->gc_data.placer); } } - fprintf(file_out, "\n"); + fprintf(file_out, "

"); if (wpt->gc_data.terr) { - fprintf(file_out, "

%s

\n", - gs_get_cachetype(wpt->gc_data.type)); - fprintf(file_out, "

%s\n", + fprintf (file_out, "

%d%s / %d%s
\n", + (int)(wpt->gc_data.diff / 10), (wpt->gc_data.diff%10)?"½":"", + (int)(wpt->gc_data.terr / 10), (wpt->gc_data.terr%10)?"½":"" ); + fprintf(file_out, "%s / %s

", + gs_get_cachetype(wpt->gc_data.type), gs_get_container(wpt->gc_data.container)); - if (wpt->gc_data.desc_short.utfstring) { - char *tmpstr = strip_nastyhtml(wpt->gc_data.desc_short.utfstring); - fprintf (file_out, "

%s

\n", tmpstr ); - xfree( tmpstr ); - } - if (wpt->gc_data.desc_long.utfstring) { - char *tmpstr = strip_nastyhtml(wpt->gc_data.desc_long.utfstring); - fprintf (file_out, "

%s

\n", tmpstr ); - xfree( tmpstr ); - } - if (wpt->gc_data.hint) { - char *hint = NULL; - if ( encrypt ) - hint = rot13( wpt->gc_data.hint ); - else - hint = xstrdup( wpt->gc_data.hint ); - fprintf (file_out, "

Hint: %s

\n", hint); - xfree( hint ); - } + } + fprintf(file_out, "
"); + if (wpt->gc_data.desc_short.utfstring) { + char *tmpstr = strip_nastyhtml(wpt->gc_data.desc_short.utfstring); + fprintf (file_out, "

%s

\n", tmpstr ); + xfree( tmpstr ); + } + if (wpt->gc_data.desc_long.utfstring) { + char *tmpstr = strip_nastyhtml(wpt->gc_data.desc_long.utfstring); + fprintf (file_out, "

%s

\n", tmpstr ); + xfree( tmpstr ); + } + if (wpt->gc_data.hint) { + char *hint = NULL; + if ( encrypt ) + hint = rot13( wpt->gc_data.hint ); + else + hint = xstrdup( wpt->gc_data.hint ); + fprintf (file_out, "

Hint: %s

\n", hint); + xfree( hint ); } else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) { - fprintf (file_out, "

%s

\n", wpt->notes); + fprintf (file_out, "

%s

\n", wpt->notes); } fs_gpx = NULL; @@ -145,17 +159,17 @@ html_disp(const waypoint *wpt) while ( curlog ) { time_t logtime = 0; struct tm *logtm = NULL; - fprintf( file_out, "

\n" ); + fprintf( file_out, "

\n" ); logpart = xml_findfirst( curlog, "groundspeak:type" ); if ( logpart ) { - fprintf( file_out, "%s by ", logpart->cdata ); + fprintf( file_out, "%s by ", logpart->cdata ); } logpart = xml_findfirst( curlog, "groundspeak:finder" ); if ( logpart ) { char *f = html_entitize( logpart->cdata ); - fprintf( file_out, "%s on ", f ); + fprintf( file_out, "%s on ", f ); xfree( f ); } @@ -165,11 +179,10 @@ html_disp(const waypoint *wpt) logtm = localtime( &logtime ); if ( logtm ) { fprintf( file_out, - "%2.2d/%2.2d/%4.4d
\n", + "%04d-%02d-%02d
\n", + logtm->tm_year+1900, logtm->tm_mon+1, - logtm->tm_mday, - logtm->tm_year+1900 - ); + logtm->tm_mday ); } } @@ -177,9 +190,7 @@ html_disp(const waypoint *wpt) if ( logpart ) { char *coordstr = NULL; float lat = 0; - int latdeg = 0; float lon = 0; - int londeg = 0; coordstr = xml_attribute( logpart, "lat" ); if ( coordstr ) { lat = atof( coordstr ); @@ -188,15 +199,11 @@ html_disp(const waypoint *wpt) if ( coordstr ) { lon = atof( coordstr ); } - latdeg = abs(lat); - londeg = abs(lon); - + coordstr = pretty_deg_format(lat, lon, degformat[2], 1); fprintf( file_out, - "%c %d° %.3f' %c %d° %.3f'
\n", - - lat < 0 ? 'S' : 'N', latdeg, 60.0 * (fabs(lat) - latdeg), - lon < 0 ? 'W' : 'E', londeg, 60.0 * (fabs(lon) - londeg) - ); + "%s
\n", + coordstr ); + xfree(coordstr); } logpart = xml_findfirst( curlog, "groundspeak:text" ); @@ -249,10 +256,15 @@ data_write(void) fprintf(file_out, "\n"); fprintf(file_out, "\n"); fprintf(file_out, " \n"); + fprintf(file_out, " \n", gpsbabel_version); fprintf(file_out, " GPSBabel HTML Output\n"); - fprintf(file_out, " \n"); if (stylesheet) fprintf(file_out, " \n", stylesheet); + else { + fprintf(file_out, " \n"); + } fprintf(file_out, "\n"); fprintf(file_out, "\n"); diff --git a/text.c b/text.c index 15085358b..ddd56bb16 100644 --- a/text.c +++ b/text.c @@ -30,6 +30,8 @@ static short_handle mkshort_handle; static char *suppresssep = NULL; static char *encrypt = NULL; static char *includelogs = NULL; +static char *degformat = NULL; +static char *altunits = NULL; #define MYNAME "TEXT" @@ -41,7 +43,12 @@ arglist_t text_args[] = { { "encrypt", &encrypt, "Encrypt hints using ROT13", NULL, ARGTYPE_BOOL, ARG_NOMINMAX }, { "logs", &includelogs, - "Include groundspeak logs if present", NULL, ARGTYPE_BOOL, ARG_NOMINMAX }, + "Include groundspeak logs if present", NULL, ARGTYPE_BOOL, ARG_NOMINMAX }, + { "degformat", °format, + "Degrees output as 'ddd', 'dmm'(default) or 'dms'", "dmm", ARGTYPE_STRING, ARG_NOMINMAX }, + { "altunits", &altunits, + "Units for altitude (f)eet or (m)etres", "m", ARGTYPE_STRING, ARG_NOMINMAX }, + ARG_TERMINATOR }; @@ -70,6 +77,8 @@ text_disp(const waypoint *wpt) gbint32 utmz; double utme, utmn; char utmzc; + char *tmpout1, *tmpout2; + char *altout; fs_xml *fs_gpx; lonint = abs((int) wpt->longitude); @@ -82,20 +91,33 @@ text_disp(const waypoint *wpt) tm = time(NULL); strftime(tbuf, sizeof(tbuf), "%d-%b-%Y", localtime(&tm)); - gbfprintf(file_out, "%-16s %c%d %06.3f %c%d %06.3f (%d%c %6.0f %7.0f)", + tmpout1 = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], 0); + if (wpt->altitude != unknown_alt) { + xasprintf(&altout, " alt:%d", (int) ( (altunits[0]=='f')?METERS_TO_FEET(wpt->altitude):wpt->altitude) ); + } + else { + altout = ""; + } + xasprintf (&tmpout2, "%s (%d%c %6.0f %7.0f)%s", tmpout1, utmz, utmzc, utme, utmn, altout ); + gbfprintf(file_out, "%-16s %59s\n", (global_opts.synthesize_shortnames) ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname, - wpt->latitude < 0 ? 'S' : 'N', abs(latint), 60.0 * (fabs(wpt->latitude) - latint), - wpt->longitude < 0 ? 'W' : 'E', abs(lonint), 60.0 * (fabs(wpt->longitude) - lonint), - utmz, utmzc, utme, utmn); - if (wpt->altitude != unknown_alt) - gbfprintf (file_out, " alt: %1.1f", wpt->altitude); - gbfprintf (file_out, "\n"); + tmpout2); + xfree(tmpout2); + xfree(tmpout1); + if (altout[0]) + xfree(altout); + + if (strcmp(wpt->description, wpt->shortname)) { - gbfprintf(file_out, "%s\n", wpt->description); - } - if (wpt->gc_data.terr) { - gbfprintf(file_out, "%s/%s\n", - gs_get_cachetype(wpt->gc_data.type), gs_get_container(wpt->gc_data.container)); + gbfprintf(file_out, "%s", wpt->description); + if (wpt->gc_data.placer) + gbfprintf(file_out, " by %s", wpt->gc_data.placer); + } + if (wpt->gc_data.terr) { + gbfprintf(file_out, " - %s / %s - (%d%s / %d%s)\n", + gs_get_cachetype(wpt->gc_data.type), gs_get_container(wpt->gc_data.container), + (int)(wpt->gc_data.diff / 10), (wpt->gc_data.diff%10)?".5":"", + (int)(wpt->gc_data.terr / 10), (wpt->gc_data.terr%10)?".5":"" ); if (wpt->gc_data.desc_short.utfstring) { char *stripped_html = strip_html(&wpt->gc_data.desc_short); gbfprintf (file_out, "\n%s\n", stripped_html); @@ -117,7 +139,7 @@ text_disp(const waypoint *wpt) } } else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) { - gbfprintf (file_out, "%s\n", wpt->notes); + gbfprintf (file_out, "\n%s\n", wpt->notes); } fs_gpx = NULL; @@ -151,11 +173,10 @@ text_disp(const waypoint *wpt) logtm = localtime( &logtime ); if ( logtm ) { gbfprintf( file_out, - "%2.2d/%2.2d/%4.4d\n", + "%4.4d-%2.2d-%2.2d\n", + logtm->tm_year+1900, logtm->tm_mon+1, - logtm->tm_mday, - logtm->tm_year+1900 - ); + logtm->tm_mday ); } } @@ -163,9 +184,7 @@ text_disp(const waypoint *wpt) if ( logpart ) { char *coordstr = NULL; float lat = 0; - int latdeg = 0; float lon = 0; - int londeg = 0; coordstr = xml_attribute( logpart, "lat" ); if ( coordstr ) { lat = atof( coordstr ); @@ -174,15 +193,9 @@ text_disp(const waypoint *wpt) if ( coordstr ) { lon = atof( coordstr ); } - latdeg = abs(lat); - londeg = abs(lon); - - gbfprintf( file_out, - "%c %d %.3f' %c %d %.3f'\n", - - lat < 0 ? 'S' : 'N', latdeg, 60.0 * (fabs(lat) - latdeg), - lon < 0 ? 'W' : 'E', londeg, 60.0 * (fabs(lon) - londeg) - ); + coordstr = pretty_deg_format(lat, lon, degformat[2], 0); + gbfprintf( file_out, "%s\n", coordstr); + xfree(coordstr); } logpart = xml_findfirst( curlog, "groundspeak:text" ); @@ -209,7 +222,7 @@ text_disp(const waypoint *wpt) } } if (! suppresssep) - gbfprintf(file_out, "-----------------------------------------------------------------------------\n"); + gbfprintf(file_out, "\n-----------------------------------------------------------------------------\n"); else gbfprintf(file_out, "\n"); diff --git a/util.c b/util.c index ad359d4c8..9fa021459 100644 --- a/util.c +++ b/util.c @@ -1210,10 +1210,52 @@ convert_human_time_format(const char *human_timef) return result; } + +/* + * Return a decimal degree pair as + * DD.DDDDD DD MM.MMM or DD MM SS.S + * fmt = ['d', 'm', 's'] + * html = 1 for html output otherwise text + */ +char * +pretty_deg_format(double lat, double lon, char fmt, int html) +{ + double latmin, lonmin, latsec, lonsec; + int latint, lonint; + char latsig, lonsig; + char *result; + latsig = lat < 0 ? 'S':'N'; + lonsig = lon < 0 ? 'W':'E'; + latint = abs((int) lat); + lonint = abs((int) lon); + latmin = 60.0 * (fabs(lat) - latint); + lonmin = 60.0 * (fabs(lon) - lonint); + latsec = 60.0 * (latmin - floor(latmin)); + lonsec = 60.0 * (lonmin - floor(lonmin)); + if (fmt == 'd') { /* ddd */ + xasprintf ( &result, "%c%6.5f%s %c%6.5f%s", + latsig, fabs(lat), html?"°":"", + lonsig, fabs(lon), html?"°":"" ); + } + else if (fmt == 's') { /* dms */ + xasprintf ( &result, "%c%d%s%02d'%04.1f\" %c%d%s%02d'%04.1f\"", + latsig, latint, html?"°":" ", (int)latmin, latsec, + lonsig, lonint, html?"°":" ", (int)lonmin, lonsec); + } + else { /* default dmm */ + xasprintf ( &result, "%c%d%s%06.3f %c%d%s%06.3f", + latsig, latint, html?"°":" ", latmin, + lonsig, lonint, html?"°":" ", lonmin); + } + return result; +} + + + /* * Get rid of potentially nasty HTML that would influence another record * that includes; - * - to stop backgrounds from being loaded + * - to stop backgrounds/background colours from being loaded * and - stop processing altogether * - stop overriding styles for everything */ @@ -1226,19 +1268,28 @@ strip_nastyhtml(const char * in) sp = returnstr = xstrdup(in); lcp = lcstr = strlower(xstrdup(in)); - while (lcp = strstr(lcstr, ""), NULL != lcp) { + sp = returnstr + (lcp - lcstr) ; /* becomes */ + sp++; *sp++ = '!'; *sp++ = ' '; *sp++ = ' '; *sp++ = ' '; + *lcp = '*'; /* so we wont find it again */ + } + while (lcp = strstr(lcstr, " */ sp = returnstr + (lcp - lcstr) ; - sp++; *sp++ = '-'; *sp++ = '-'; *sp++ = '-'; *sp++ = '-'; + sp++; *sp++ = '!'; *sp++ = '-'; *sp++ = '-'; + while ( (*sp) && (*sp != '>') ) { + sp++; + } + *--sp = '-'; *--sp = '-'; *lcp = '*'; /* so we wont find it again */ } - while (lcp = strstr(lcstr, ""), NULL != lcp) { + sp = returnstr + (lcp - lcstr) ; /* becomes